﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using Entity;
using DataControls;


namespace GiaoVien_QuanLy_DeTai
{
    public partial class REPORT_LUONGKN_Form : Form
    {
        public REPORT_LUONGKN_Form()
        {
            InitializeComponent();
        }

        private void REPORT_LUONGKN_Form_Load(object sender, EventArgs e)
        {
            txtNamHoc.Text = DateTime.Now.Year.ToString();
            this.ReportLuongKN.RefreshReport();
        }

        private void btnBaoCao_Click(object sender, EventArgs e)
        {
            int nh=0;
            if (nmHocKi.Value <= 0 || nmHocKi.Value >= 20)
            {
                MessageBox.Show("Ban nhap hoc ki sai");
                return;
            }
            else
            try
            {
                if ((nh = Convert.ToInt16(txtNamHoc.Text)) <= 1990)
                {
                    MessageBox.Show("Ban nhap nam hoc chua chinh xac");
                }
                else
                {
                    SqlConnection cnn = new SqlConnection(" Server = COLDBOY-MSI ;"
                                                        + " Database = CVHT_HDDT;"
                                                        + " Integrated Security = True");

                    SqlDataAdapter adapter = new SqlDataAdapter("SELECT G.TENGV, B.* FROM BANGLUONGKN B, GIAOVIEN G WHERE B.MAGV= G.MAGV "+
                                                                                "AND  HOCKI=" + (int)nmHocKi.Value + 
                                                                                "AND NAMHOC="+ nh, cnn);
                    DataSet ds = new DataSet();
                    adapter.Fill(ds, "BANGLUONGKN");

                    //load report
                    LUONGKN_Report rp = new LUONGKN_Report();
                    rp.SetDataSource(ds);
                    ReportLuongKN.ReportSource = rp;
                    ReportLuongKN.Refresh();
                }
            }
            catch(Exception ex)
            {
                MessageBox.Show("Nhập hocki/năm. \n"+ ex.Message);
                return;
            }
        }
    }
}
